const mongoose = require('mongoose');

const taskSchema = new mongoose.Schema({
  text: {
    type: String,
    required: true
  },
  points: {
    type: Number,
    required: true
  }
});

const challengeSchema = new mongoose.Schema({
  title: {
    type: String,
    required: true
  },
  description: {
    type: String,
    required: true
  },
  points: {
    type: Number,
    required: true
  },
  duration: {
    type: String,
    required: true
  },
  category: {
    type: String,
    required: true
  },
  difficulty: {
    type: String,
    enum: ['简单', '中等', '困难'],
    required: true
  },
  icon: {
    type: String,
    required: true
  },
  tasks: [taskSchema],
  tips: String,
  isActive: {
    type: Boolean,
    default: true
  },
  participants: [{
    userId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'User'
    },
    startDate: Date,
    progress: {
      type: Number,
      default: 0
    },
    completedTasks: [Number],
    status: {
      type: String,
      enum: ['active', 'completed', 'abandoned'],
      default: 'active'
    }
  }]
}, { timestamps: true });

module.exports = mongoose.model('Challenge', challengeSchema); 